package sdk.android.callrecorder.lv.adapter;

import java.util.ArrayList;

import sdk.android.callrecorder.R;
import sdk.android.callrecorder.data.CallNumber;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CallNumberListAdapter extends ArrayAdapter<CallNumber> {

	public CallNumberListAdapter(Context context, ArrayList<CallNumber> items) {
		super(context, R.layout.list_row_call_numbers, items);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(getContext());
			convertView = inflater.inflate(R.layout.list_row_call_numbers, null);

			convertView.setTag(R.id.tv_call_name, convertView.findViewById(R.id.tv_call_name));
			convertView.setTag(R.id.tv_call_number, convertView.findViewById(R.id.tv_call_number));
		}

		CallNumber data = getItem(position);

		convertView.setTag(data);

		((TextView) convertView.getTag(R.id.tv_call_name)).setText(data.name);
		((TextView) convertView.getTag(R.id.tv_call_number)).setText(data.callNumber);

		return convertView;
	}
}
